function EventIsTeam(event, team) {
    return ($(event).attr('team') == $(team).attr('name'));
}
function EventIsSkater(event, skater, team) {
    return ($(event).attr('team') == $(team).attr('name')) &&
        ($(event).attr("skater") == $(skater).attr("number"));
}
function PeriodScore(period, team) {
    var retval = 0;
    $(period).find('jam pass').each(function (index, pass) {
        if (EventIsTeam(pass, team)) {
            retval += Number($(pass).attr('points'))
        }
    })
    return retval;
}
function MajorPenalties(period, team) {
    var retval = 0;
    $(period).find('jam penalty').each(function (index, penalty) {
        if (EventIsTeam(penalty, team)) {
            retval += 1
        }
    })
    return retval;
}
function JamPoints(jam, team) {
    var retval = 0;
    $(jam).find('pass').each(function (index, pass) {
        if (EventIsTeam(pass, team)) {
            retval += Number($(pass).attr('points'))
        }
    })
    return retval;
}
function JamDuration(jam) {
    var retval = 120;
    if ($(jam).find('call').length) {
        retval = 90;
    }
    return retval;
}
function JamCalled(jam,team) {
    var retval = false;
    $(jam).find('call').each(function (index, call) {
        if (EventIsTeam(call, team)) {
            retval = true;
        }
    });
    return retval;
}
function JamLost(jam,team) {
    var retval = false;
    $(jam).find('lost').each(function (index, lost) {
        if (EventIsTeam(lost, team)) {
            retval = true;
        }
    });
    return retval;
}
function JamLead(jam,team) {
    var retval = false;
    $(jam).find('lead').each(function (index, lead) {
        if (EventIsTeam(lead, team)) {
            retval = true;
        }
    });
    return retval;
}
function JamNP(jam,team) {
    var retval = true;
    $(jam).find('pass').each(function (index, pass) {
        if (EventIsTeam(pass, team) && Number($(pass).attr("number")) > 1) {
            retval = false;
        }
    });
    return retval;
}
function JamStarPass(jam,team) {
    var retval = false;
    $(jam).find('star-pass').each(function (index, pass) {
        if (EventIsTeam(pass, team)) {
            retval = true;
        }
    });
    return retval;
}
function JamInj(jam) {
    if ($(jam).find('inj').length)
        return true;
    return false;
}

function SkaterPositionInJam(skater,team, jam) {
    var retval = null;
    $(jam).find('lineup').each(function(index, value) {
        if (EventIsSkater(value, skater, team)) {
            retval = $(value).attr("position");
        }
    })
    return retval;
}
function PositionsInJam(jam, team) {
    var retval = { blockers: [] };
    $(jam).find('lineup').each(function(index, value) {
        if (EventIsTeam(value, team)) {
            var pos = $(value).attr("position");
            var sknum = $(value).attr("skater");
            if (pos && sknum) {
                if (pos == "blocker") {
                    retval.blockers.push(sknum);
                } else {
                    retval[pos] = sknum;
                }
            }
        }
    });
    return retval;
}
function JamScoringPassesWithStarPass(jam, team, starPass) {
    var retval = [];
    var foundStarPass = false;
    $(jam).find('pass, star-pass').each(function(index, value) {
        if (EventIsTeam(value, team)) {
            if (value.tagName == "star-pass") {
                foundStarPass = true;
            } else if (starPass && !foundStarPass) {
                retval.push("-");
            } else if (starPass == false && foundStarPass) {
                retval.push("*");
            } else {
                retval.push(value);
            }
        }
    });
    return retval;
}
function JamScoringPasses(jam, team) {
    var retval = [];
    $(jam).find('pass').each(function(index, value) {
        if (EventIsTeam(value, team)) {
            retval.push(value);
        }
    });
    return retval;
}
function JamStarPassPass(jam,team) {
    var retval = 0;
    var done = false;
    $(jam).find('pass, star-pass').each(function (index, pass) {
        if (EventIsTeam(pass, team)) {
            if (pass.tagName == "star-pass") {
                done = true;
                retval += 1;
            } else if (!done) {
                retval += 1;
            }
        }
    });
    if (done)
        return retval;
    return 0;
}
